import _regeneratorRuntime from "@babel/runtime/regenerator";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
import request from 'utils/request';
import { CPAAS_PLATFORM } from 'utils/config';
import { parseParameters, getCurrentOrganizationId, isTenantRoleLevel } from 'utils/utils';
var organizationId = getCurrentOrganizationId();
var urlPrefix = "".concat(CPAAS_PLATFORM, "/v1").concat(isTenantRoleLevel() ? "/".concat(organizationId, "/") : "/");
/**
 * 查询规则引擎表数据
 * @async
 * @function fetchTableList
 * @param {object} params - 查询条件
 * @param {!number} [params.page = 0] - 数据页码
 * @param {!number} [params.size = 10] - 分页大小
 * @returns {object} fetch Promise
 */

export function fetchTableList(_x) {
  return _fetchTableList.apply(this, arguments);
}
/**
 * 查询规则引擎明细
 * @async
 * @function searchDetail
 * @param {object} params - 查询条件
 * @param {?string} params.ruleScriptId - 规则引擎Id
 * @returns {object} fetch Promise
 */

function _fetchTableList() {
  _fetchTableList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    var param;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            param = parseParameters(params);
            return _context.abrupt("return", request("".concat(urlPrefix, "rule-scripts"), {
              method: 'GET',
              query: _objectSpread({}, param)
            }));

          case 2:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _fetchTableList.apply(this, arguments);
}

export function searchDetail(_x2) {
  return _searchDetail.apply(this, arguments);
}
/**
 * 添加规则引擎
 * @async
 * @function createRuleEngine
 * @param {object} params - 请求参数
 * @param {!object} params.tenantId - 租户
 * @param {!string} params.serverName - 服务名称
 * @param {?number} params.scriptCode - 脚本编码
 * @param {!object} params.tenantId - 租户
 * @param {!string} params.scriptDescription - 描述
 * @param {?number} params.scriptTypeCode - 类型
 * @param {!string} params.enabledFlag - 启用标记
 * @param {?number} params.scriptContent - 脚本内容
 * @returns {object} fetch Promise
 */

function _searchDetail() {
  _searchDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request("".concat(urlPrefix, "rule-scripts/").concat(params.ruleScriptId), {
              method: 'GET'
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _searchDetail.apply(this, arguments);
}

export function createRuleEngine(_x3) {
  return _createRuleEngine.apply(this, arguments);
}
/**
 * 编辑规则引擎
 * @async
 * @function editRuleEngine
 * @param {object} params - 请求参数
 * @param {!object} params.tenantId - 租户
 * @param {!string} params.serverName - 服务名称
 * @param {?number} params.scriptCode - 脚本编码
 * @param {!object} params.tenantId - 租户
 * @param {!string} params.scriptDescription - 描述
 * @param {?number} params.scriptTypeCode - 类型
 * @param {!string} params.enabledFlag - 启用标记
 * @param {?number} params.scriptContent - 脚本内容
 * @param {!string} params.ruleScriptId - ruleScriptId
 * @param {!string} params.objectVersionNumber - 版本号
 * @returns {object} fetch Promise
 */

function _createRuleEngine() {
  _createRuleEngine = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request("".concat(urlPrefix, "rule-scripts"), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _createRuleEngine.apply(this, arguments);
}

export function editRuleEngine(_x4) {
  return _editRuleEngine.apply(this, arguments);
}
/**
 * 删除规则引擎
 * @async
 * @function deleteRuleEngine
 * @param {object} params - 规则引擎
 * @returns {object} fetch Promise
 */

function _editRuleEngine() {
  _editRuleEngine = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request("".concat(urlPrefix, "rule-scripts"), {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _editRuleEngine.apply(this, arguments);
}

export function deleteRuleEngine(_x5) {
  return _deleteRuleEngine.apply(this, arguments);
}
/**
 * 测试规则引擎
 * @param {object} params - 请求参数
 */

function _deleteRuleEngine() {
  _deleteRuleEngine = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            return _context5.abrupt("return", request("".concat(urlPrefix, "rule-scripts"), {
              method: 'DELETE',
              body: params
            }));

          case 1:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _deleteRuleEngine.apply(this, arguments);
}

export function testRuleEngine(_x6) {
  return _testRuleEngine.apply(this, arguments);
}

function _testRuleEngine() {
  _testRuleEngine = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(params) {
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            return _context6.abrupt("return", request("".concat(urlPrefix, "rule-scripts/test"), {
              method: 'POST',
              body: _objectSpread({}, params)
            }));

          case 1:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _testRuleEngine.apply(this, arguments);
}